package com.ficus.road.maintain.core.model.taskInfo;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author lijiawei
 * @date 2023/10/10 下午4:01
 */
class ZhongHaiDateDeserializer extends JsonDeserializer<LocalDateTime> {

    private String format = "yyyy-MM-dd'T'HH:mm:ss";
    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);

    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String dateString = p.readValueAs(String.class);
        String dateStr = dateString.replaceAll("\\s+", "");
        return LocalDateTime.parse(dateStr, dateTimeFormatter);
    }
}
